<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:ibba.src.sl.componentes">

    <local:HeaderVisibilityConverter x:Key="HeaderVisibilityConverter"/>
    
    <Style TargetType="local:CustomButtonBar">
        <Setter Property="IsTabStop" Value="True" />
        <Setter Property="Content" Value="CustomButtonBar" />        
        <Setter Property="Background" Value="Transparent"/>        
        <Setter Property="Cursor" Value="Hand" />
        <Setter Property="ImageSizeNormal" Value="40" />
        <Setter Property="ImageSizeOver" Value="60" />
        <Setter Property="IsAnimate" Value="True"/>
        <Setter Property="Template">            
            <Setter.Value>
                <ControlTemplate TargetType="local:CustomButtonBar">
                    <Grid x:Name="RootElement">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualStateGroup.Transitions>
                                    <VisualTransition To="Normal" GeneratedDuration="0:0:0.3" />
                                    <VisualTransition To="Over" GeneratedDuration="0:0:0.1" />
                                </VisualStateGroup.Transitions>
                                
                                <VisualState x:Name="Normal"/>                                
                                <VisualState x:Name="Over">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="imgBotao"
                                                         Storyboard.TargetProperty="Height"
                                                         To="{Binding ElementName=panelImage, Path=ActualWidth}" 
                                                         Duration="0:00:00.1"/>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>

                        <Grid Width="{TemplateBinding Width}" 
							  Height="{TemplateBinding Height}" 
                              Cursor="{TemplateBinding Cursor}" 
                              Margin="0">

                            <StackPanel Orientation="Vertical" Margin="5" VerticalAlignment="Bottom">
                                <Grid Name="panelImage"
                                            HorizontalAlignment="Center" VerticalAlignment="Bottom"
                                            Width="{TemplateBinding ImageSizeOver}" Height="{TemplateBinding ImageSizeOver}">
                                    
                                    <Image x:Name="imgBotao" Stretch="Uniform"
                                           Source="{TemplateBinding Image}" 
                                           Width="{TemplateBinding ImageSizeOver}" Height="{TemplateBinding ImageSizeNormal}"
                                           HorizontalAlignment="Center" VerticalAlignment="Bottom" />

                                </Grid>
                                
                                <ContentControl Content="{TemplateBinding Content}"                                                
                                                HorizontalAlignment="Center" 
                                                VerticalAlignment="Bottom"
                                                FontFamily="{TemplateBinding FontFamily}" 
                                                FontSize="{TemplateBinding FontSize}" 
                                                FontStretch="{TemplateBinding FontStretch}" 
                                                Foreground="{TemplateBinding Foreground}" />
                            </StackPanel>                            
                        </Grid>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
    <!-- CustomContentControl -->
    <Style TargetType="local:CustomContentControl">
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="Foreground" Value="Black" />
        <Setter Property="BorderBrush" Value="Transparent" />
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="HorizontalAlignment" Value="Stretch" />
        <Setter Property="VerticalAlignment" Value="Stretch" />
        <Setter Property="HorizontalContentAlignment" Value="Left" />
        <Setter Property="VerticalContentAlignment" Value="Top" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:CustomContentControl">
                    <Border Background="{TemplateBinding Background}" BorderBrush="#87AFDA" BorderThickness="1">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="*" />
                            </Grid.RowDefinitions>

                            <Border Grid.Column="0" Grid.Row="0" Background="#D4E6FC" BorderThickness="0,0,0,1" BorderBrush="#87AFDA">
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition />
                                        <ColumnDefinition Width="20" />
                                    </Grid.ColumnDefinitions>

                                    <ContentControl Content="{TemplateBinding Header}" 
                                                    BorderBrush="Transparent" BorderThickness="0"
                                                    HorizontalAlignment="Stretch" VerticalAlignment="Stretch" 
                                                    HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" 
                                                    Foreground="#224499" 
                                                    FontWeight="Bold" 
                                                    FontFamily="Portable User Interface" 
                                                    FontSize="12" Margin="3,3,3,3" />

                                    <!--<HyperlinkButton x:Name="hlbClose" Grid.Column="1" Content="[X]" />-->
                                </Grid>
                            </Border>

                            <!-- 
                            HorizontalAlignment="{TemplateBinding HorizontalAlignment}" 
                                            HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" 
                                            VerticalAlignment="{TemplateBinding VerticalAlignment}" 
                                            VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                            -->
                            <ContentControl Grid.Column="0" Grid.Row="1" 
                                            Content="{TemplateBinding Content}" 
                                            ContentTemplate="{TemplateBinding ContentTemplate}" 
                                            HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                                            Cursor="{TemplateBinding Cursor}"                                             
                                            FontFamily="{TemplateBinding FontFamily}" 
                                            FontSize="{TemplateBinding FontSize}" 
                                            FontStretch="{TemplateBinding FontStretch}" 
                                            Foreground="{TemplateBinding Foreground}" 
                                            Margin="{TemplateBinding Padding}" />
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    
    <Style TargetType="local:CustomContentPanel">
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="BackgroundHeader" Value="WhiteSmoke" />
        <Setter Property="Foreground" Value="Black" />
        <Setter Property="BorderBrush" Value="Gray" />
        <Setter Property="BorderThickness" Value="2" />
        <Setter Property="CornerRadius" Value="12" />
        <Setter Property="Padding" Value="5,10" />
        <Setter Property="HeaderPadding" Value="10,2,10,2" />
        <Setter Property="HorizontalAlignment" Value="Stretch" />
        <Setter Property="VerticalAlignment" Value="Stretch" />
        <Setter Property="HorizontalContentAlignment" Value="Left" />
        <Setter Property="VerticalContentAlignment" Value="Top" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:CustomContentPanel">

                    <Grid Width="{TemplateBinding Width}" Height="{TemplateBinding Height}">
                        <Border BorderBrush="{TemplateBinding BorderBrush}" 
                                BorderThickness="{TemplateBinding BorderThickness}" 
                                CornerRadius="{TemplateBinding CornerRadius}"                                
                                Margin="0,10,0,0" Padding="5,10,5,5">
                            <Grid>

                                <ContentControl Content="{TemplateBinding Content}" 
                                                ContentTemplate="{TemplateBinding ContentTemplate}" 
                                                HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" 
                                                VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                                                Cursor="{TemplateBinding Cursor}"
                                                Margin="{TemplateBinding Padding}"
                                                />
                            
                            </Grid>
                        </Border>

                        <Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1" CornerRadius="6" 
                                Background="{TemplateBinding BackgroundHeader}"                                         
                                VerticalAlignment="Top" HorizontalAlignment="Left" 
                                Padding="{TemplateBinding HeaderPadding}"
                                Margin="20,0,0,0" 
                                Visibility="{Binding Text, ElementName=txtHeader, Converter={StaticResource HeaderVisibilityConverter}}">
                            
                            <TextBlock Name="txtHeader" Text="{TemplateBinding Header}"
                                       Foreground="{TemplateBinding Foreground}"
                                       FontFamily="{TemplateBinding FontFamily}" 
                                       FontSize="{TemplateBinding FontSize}" 
                                       FontStretch="{TemplateBinding FontStretch}"/>
                        </Border>
                    </Grid>
                    
                    
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
    <Style TargetType="local:SwitchControl">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:SwitchControl">

                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            Padding="{TemplateBinding Padding}">

                        <ContentPresenter x:Name="Content" />
                    </Border>

                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>


    <Style TargetType="local:FlipPanel">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:FlipPanel">
                    <Grid>                        
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="ViewStates">
                                <VisualStateGroup.Transitions>
                                    <VisualTransition To="Normal" From="Flipped" GeneratedDuration="0:0:0.3">
                                        <Storyboard>
                                            <DoubleAnimation Storyboard.TargetName="BackContentProjection" Storyboard.TargetProperty="RotationY" To="-90" Duration="0:0:0.1"/>
                                            <DoubleAnimation Storyboard.TargetName="FrontContentProjection" Storyboard.TargetProperty="RotationY" To="0" BeginTime="0:0:0.1" Duration="0:0:0.2"/>
                                        </Storyboard>
                                    </VisualTransition>
                                    <VisualTransition To="Flipped" From="Normal" GeneratedDuration="0:0:0.3">
                                        <Storyboard>
                                            <DoubleAnimation Storyboard.TargetName="FrontContentProjection" Storyboard.TargetProperty="RotationY" To="90" Duration="0:0:0.1"/>
                                            <DoubleAnimation Storyboard.TargetName="BackContentProjection" Storyboard.TargetProperty="RotationY" To="0" BeginTime="0:0:0.1" Duration="0:0:0.2"/>
                                        </Storyboard>
                                    </VisualTransition>
                                </VisualStateGroup.Transitions>
                                <VisualState x:Name="Normal">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="BackContentProjection" Storyboard.TargetProperty="RotationY" To="-90" Duration="0"/>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Flipped">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="FrontContentProjection" Storyboard.TargetProperty="RotationY" To="90" Duration="0"/>
                                        <DoubleAnimation Storyboard.TargetName="FlipButtonTransform" Storyboard.TargetProperty="Angle" To="90" Duration="0"/>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <Border BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                CornerRadius="{TemplateBinding CornerRadius}"
                                Background="{TemplateBinding Background}">
                            
                            <ContentPresenter Content="{TemplateBinding FrontContent}"/>
                            
                            <Border.Projection>
                                <PlaneProjection x:Name="FrontContentProjection"/>
                            </Border.Projection>
                        </Border>
                        <Border BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                CornerRadius="{TemplateBinding CornerRadius}"
                                Background="{TemplateBinding Background}">
                            
                            <ContentPresenter Content="{TemplateBinding BackContent}"/>
                            
                            <Border.Projection>
                                <PlaneProjection x:Name="BackContentProjection"/>
                            </Border.Projection>
                        </Border>
                        <ToggleButton Grid.Row="1" RenderTransformOrigin="0.5,0.5" Margin="0,10,0,0" x:Name="FlipButton">
                            <ToggleButton.Template>
                                <ControlTemplate>
                                    <Grid>
                                        <Ellipse Width="20" Height="20" Stroke="#FFA9A9A9" Fill="AliceBlue"/>
                                        <Path RenderTransformOrigin="0.5,0.5" HorizontalAlignment="Center" VerticalAlignment="Center" Data="M1,1.5L4.5,5 8,1.5" Stroke="#FF666666" StrokeThickness="2" />
                                    </Grid>
                                </ControlTemplate>
                            </ToggleButton.Template>
                            <ToggleButton.RenderTransform>
                                <RotateTransform Angle="-90" x:Name="FlipButtonTransform"/>
                            </ToggleButton.RenderTransform>
                        </ToggleButton>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>

